import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请键入内容:");
        String input = scanner.nextLine();
        System.out.println("你输入的是" + input);
        char[] charArray = input.toCharArray();//用于将字符串转换为字符数组,会生成一个新的数组

        for (int i = 0; i < charArray.length; i++) {
            System.out.println("第" + i + "个是:" + charArray[i]);
        }
        boolean isPalindrome = true;//设置布尔变量来跟踪是否是回文数，如果不是布尔值为false并退出循环
        char[] element = new char[2];

        if (charArray.length % 2 == 0) {
            for (int i = 0; i < charArray.length / 2; i++) {
                element[0] = charArray[i];
                element[1] = charArray[charArray.length - 1 - i];
                System.out.println("此时的element[0]" + "是" + charArray[i]);
                System.out.println("此时的element[1]" + "是" + charArray[charArray.length - 1 - i]);
                if (element[0] != element[1]) {
                    System.out.println(input + "不是回文数!");
                    isPalindrome = false;
                    break;
                }
            }
        } else {
            for (int i = 0; i < (charArray.length - 1) / 2; i++) {
                element[0] = charArray[i];
                element[1] = charArray[charArray.length - 1 - i];
                System.out.println("此时的element[0]" + "是" + charArray[i]);
                System.out.println("此时的element[1]" + "是" + charArray[charArray.length - 1 - i]);
                if (element[0] != element[1]) {
                    System.out.println(input + "不是回文数!");
                    isPalindrome = false;
                    break;
                }
            }
        }
        if (isPalindrome == true) {
            System.out.println(input + "是回文数!");
        }
    }
}
